//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  NotificationId.cs
//    
// Abstract:
//
//  This module implements the NotificationId class. The NotificationId class encapsulates the unique ID for a notification.
//  
//--

using System;
using System.Diagnostics;

namespace Microsoft.EnhancedReminders
{
    /// <summary>
    /// Encapsulates the ID string and mailbox name for a given notification.
    /// </summary>
    [Serializable]
    public sealed class NotificationId
    {
        private string _mailItemId;
        private string _mailChangeKey;
        private string _name;
        private Guid _internalId;

        /// <summary>
        /// Default ctor.
        /// </summary>
        public NotificationId()
        {
        }

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="mailItemId">Mailbox item ID for the associated notification</param>
        /// <param name="name">Name of the mailbox for the associated notification</param>
        public NotificationId(string mailItemId, string name)
        {
            Debug.Assert(!String.IsNullOrEmpty(mailItemId), "!String.IsNullOrEmpty(id)");
            Debug.Assert(!String.IsNullOrEmpty(name), "!String.IsNullOrEmpty(name)");

            _mailItemId = mailItemId;
            _name = name;
            _internalId = Guid.NewGuid();
        }

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="mailItemId">Mailbox item ID for the associated notification</param>
        /// <param name="name">Name of the mailbox for the associated notification</param>
        /// <param name="mailChangeKey">Change key for the mailbox item for the associated notification.</param>
        public NotificationId(string mailItemId, string name, string mailChangeKey) : this(mailItemId, name)            
        {
            Debug.Assert(!String.IsNullOrEmpty(mailItemId), "!String.IsNullOrEmpty(id)");
            Debug.Assert(!String.IsNullOrEmpty(name), "!String.IsNullOrEmpty(name)");

            _mailChangeKey = mailChangeKey;
        }

        /// <summary>
        /// Determines if this instance is equal to the specified notificationId instance.
        /// </summary>
        /// <param name="notificationId">notificationId instance to be compared against</param>
        /// <returns>
        /// true if this instance is equal to the specified notificationId instance; false otherwise.
        /// </returns>
        public bool Equals(NotificationId notificationId)
        {
            Debug.Assert(notificationId != null, "notificationId != null");

            return _mailItemId == notificationId._mailItemId && _internalId.Equals(notificationId._internalId);
        }

        /// <summary>
        /// Unique ID.
        /// </summary>
        public string Id
        {
            get
            {
                return _mailItemId;
            }
        }

        /// <summary>
        /// Returns the ChangeKey for the MailItem that this notification is for.
        /// </summary>
        public string ChangeKey
        {
            get
            {
                return _mailChangeKey;
            }
        }

        /// <summary>
        /// Produces a string representation of this object.
        /// </summary>
        /// <returns>
        /// The string representation of this object.
        /// </returns>
        /// <remarks>
        /// This is used in logging.
        /// </remarks>
        public override string ToString()
        {
            return _internalId.ToString();
        }

        /// <summary>
        /// Mailbox name for the associated reminder.
        /// </summary>
        public string Name
        {
            get
            {
                return _name;
            }
        }
    }
}
